/*数量加减操作*/
function span_jian(e){
    var shu = $(e).next().val();
    if(shu>1){
        shu = parseInt(shu)-1;
        $(e).next().val(shu);
        $(e).parents(".item-inner").find(".liang-numder span").html(shu);
    }
}
function span_jia(e){
    var shu = $(e).prev().val();
    shu = parseInt(shu)+1;
    $(e).prev("input").val(shu);
    $(e).parents(".item-inner").find(".liang-numder span").html(shu);
}
//添加购物车
function add_cart_(status,id,count){
	if(!count){
		count = 1;
	}
	
	request_(
		url_('api/V1/cart_add')
		,{
			goods_id: id
			,count: count
			,community_id: SESSION.get_community_id()
		}
		,function(d){
			if (d.code == 0) {
		        //do something
		        if (status == 0) {
		        	my_tips_('添加成功')
		        } else if(status == 1){//商品详情 立即购买
		        	my_tips_('前往下单',function(){
		        		go_href_('#/shopping_car')
		        	})
		        }else if(status == 2){//购物车内添加  重新加载数据
		        	SHOPPING_CAR.user_cart();
		        }
		        user_cart_count();
		    }else if(d.code == 1011){
		    	my_tips_(d.msg,function(){
		    		go_href_('#/login');
		    	})
		    }else {
		        my_tips_(d.msg);
		    }
		}
	);
}
function shoucang(id){
	request_(
		url_('api/V4/shoucang_edit')
		,{
			goods_id: id
			,op: "add"
			,community_id: Storage_.get('community_id')?Storage_.get('community_id'):''
		}
		,function(d){
			if (d.code == 0) {
		        //do something
		        my_tips_('收藏商品成功');
		        $('.commodity_detail_shoucang img').attr('src','img/soucang2.jpg');
		    } else if(d.code == 1032){
		        my_tips_(d.msg);
		        $('.commodity_detail_shoucang img').attr('src','img/soucang2.jpg');
		    }else{
		        my_tips_(d.msg);
		    }
		}
	);
}
//获取用户购物车上标数量
function user_cart_count(){
	var url = url_('api/V1/user_cart_count');
	var data = {'community_id':SESSION.get_community_id()};
	var success = function(d){
		if (d.code == 0) {
			$('#shopCar_count_container').html(d.data.cart_sum)
//			val1 = d.data.cart_sum;
//			val2 = document.getElementById('shopCar_count_container')
//			user = {}
//			Object.defineProperty(user, 'name', {
//			  get: function() { return val1; }, 
//			  set: function(newValue) { val1 = newValue; val2.html = newValue; },
//			  configurable: true
//			});
//			user.name = user.name  // 同步两个val
//			val2.innerHTML = val2.html;
		} else if (d.code == 1011) {
			my_tips_(d.msg,function(){
				go_("login");
			})
		} else{
			my_tips_(d.msg);
		}
	}
	request_(url,data,success)
}
user_cart_count();
